package com.javaweb.controller;

import com.javaweb.Response.ResponseResult;
import com.javaweb.model.User;
import com.javaweb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/blog-api/v0.1/user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/list")
    public ResponseResult<List<User>> list(@RequestBody User user){
        return ResponseResult.ok(userService.findUserByName(user.getName()));
    }
    @PostMapping("/add")
    public ResponseResult<Object> add(@RequestBody User user){
        userService.login(user.getName(),user.getPassword());
        return ResponseResult.ok(null,"新增成功");
    }
    @PostMapping("/password/change")
    public ResponseResult<Object> changePassword(@RequestParam String userId,@RequestParam String newPassword ){
            userService.changePassword(userId,newPassword);
            return ResponseResult.ok(null,"修改成功");
    }

}
